Abstraction עזאם מרעי המחלקה למדעי המחשב אוניברסיטת בן-גוריון

Similar documents
Chapter Seven: Regular Expressions

Lecture 1. Abstraction

Classes and Methods עזאם מרעי המחלקה למדעי המחשב אוניברסיטת בן-גוריון מבוסס על השקפים של אותו קורס שניתן בשנים הקודמות

Chapter Seven: Regular Expressions. Formal Language, chapter 7, slide 1

Classes and Methods לאוניד ברנבוים המחלקה למדעי המחשב אוניברסיטת בן-גוריון

The Stack ADT. Stacks. The Stack ADT. The Stack ADT. Set of objects in which the location an item is inserted and deleted is prespecified.

Object interconnections גרא וייס המחלקה למדעי המחשב אוניברסיטת בן-גוריון

Object Oriented Software Design

Abstraction. Abstraction

Classes and Methods גרא וייס המחלקה למדעי המחשב אוניברסיטת בן-גוריון

Chapter 13 Object Oriented Programming. Copyright 2006 The McGraw-Hill Companies, Inc.

MIT Specifying Languages with Regular Expressions and Context-Free Grammars

Object-Oriented Design גרא וייס המחלקה למדעי המחשב אוניברסיטת בן-גוריון

Static and Dynamic Behavior עזאם מרעי המחלקה למדעי המחשב אוניברסיטת בן-גוריון מובסס על הרצאות של אותו קורס שניתן בשנים הקודמות ע "י ד"ר גרא וייס

Inheritance and Substitution גרא וייס המחלקה למדעי המחשב אוניברסיטת בן-גוריון

Lecture No.04. Data Structures

Implications of Substitution עזאם מרעי המחלקה למדעי המחשב אוניברסיטת בן-גוריון

Inheritance and Substitution עזאם מרעי המחלקה למדעי המחשב אוניברסיטת בן-גוריון מובסס על הרצאות של אותו קורס שניתן בשנים הקודמות ע"י ד"ר גרא וייס

MIT Specifying Languages with Regular Expressions and Context-Free Grammars. Martin Rinard Massachusetts Institute of Technology

Outline and Reading. The Stack ADT ( 4.2.1) Applications of Stacks ( 4.2.3) Array-based implementation ( 4.2.2) Growable array-based stack.

Short Notes of CS201

Object- Oriented Design with UML and Java Part I: Fundamentals

CS 10, Fall 2015, Professor Prasad Jayanti

Design Patterns גרא וייס המחלקה למדעי המחשב אוניברסיטת בן-גוריון

CS201 - Introduction to Programming Glossary By

Complexity Theory. Compiled By : Hari Prasad Pokhrel Page 1 of 20. ioenotes.edu.np

Software Architecture

Object Oriented Design: Identifying Objects

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING

Object-oriented perspective

Inheritance. OOP components. Another Example. Is a Vs Has a. Virtual Destructor rule. Virtual Functions 4/13/2017

Overloading המחלקה למדעי המחשב עזאם מרעי אוניברסיטת בן-גוריון

Outline. Example stack Version 1 -- int stack with fixed array Version 2 -- int stack with flexible array Version 3 -- with interface

Stacks. Common data structures - useful for organizing data for specific tasks Lists Stacks - an Abstract Data Type

JAVA: A Primer. By: Amrita Rajagopal

IT 4043 Data Structures and Algorithms. Budditha Hettige Department of Computer Science

FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- OCTOBER, 2012 DATA STRUCTURE

CS 370 Design Heuristics D R. M I C H A E L J. R E A L E F A L L

Non-deterministic Finite Automata (NFA)

Languages and Compilers

1.00 Lecture 26. Data Structures: Introduction Stacks. Reading for next time: Big Java: Data Structures

Programming Languages 2nd edition Tucker and Noonan"

Lecture 6. COMP1006/1406 (the OOP course) Summer M. Jason Hinek Carleton University

Software Architecture (Lesson 2) Object-Oriented Paradigm (1)

Structured Programming

More Data Structures (Part 1) Stacks

Concepts of Programming Languages

Software Service Engineering

CHAPTER 5 GENERAL OOP CONCEPTS

Introduction to Object- Oriented Programming

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Compiler Design

Object-Oriented Programming (OOP) Fundamental Principles of OOP

M301: Software Systems & their Development. Unit 4: Inheritance, Composition and Polymorphism

CSI33 Data Structures

Programming, Data Structures and Algorithms Prof. Hema Murthy Department of Computer Science and Engineering Indian Institute of Technology, Madras

Object-Oriented Languages and Object-Oriented Design. Ghezzi&Jazayeri: OO Languages 1

CS 216 Exam 1 Fall SOLUTION

An OBJECT contains VARIABLES = PROPERTIES and METHODS = BEHAVIORS. Outline the general nature of an object.

C++ Programming: Introduction to C++ and OOP (Object Oriented Programming)

Overriding המחלקה למדעי המחשב עזאם מרעי אוניברסיטת בן-גוריון

Assignment 5. Introduction

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

EEL 3801 Introduction to Computer Engineering Summer Home Work Schedule

Classes, subclasses, subtyping

User. Application program. Interfaces. Operating system. Hardware

CLASSIC DATA STRUCTURES IN JAVA

for (i=1; i<=100000; i++) { x = sqrt (y); // square root function cout << x+i << endl; }

The University Of Michigan. EECS402 Lecture 06. Andrew M. Morgan. Savitch Ch. 6 Intro To OOP Classes Objects ADTs.

Stacks. stacks of dishes or trays in a cafeteria. Last In First Out discipline (LIFO)

Static and Dynamic Behavior לאוניד ברנבוים המחלקה למדעי המחשב אוניברסיטת בן-גוריון

ENCAPSULATION. private, public, scope and visibility rules. packages and package level access.

Data Structures and Algorithms

Procedure and Object- Oriented Abstraction

Exception Handling: A False Sense of Security Cargill, P1

Ch 1: The Architecture Business Cycle

Regular Expressions. Chapter 6

Dot and Scope Resolution Operator

CS111: PROGRAMMING LANGUAGE II. Lecture 1: Introduction to classes

Programming Lecture 3

In One Slide. Outline. LR Parsing. Table Construction

Chapter 1: Object-Oriented Programming Using C++


A STUDY OF OBJECT ORIENTED ANALYSIS AND DESIGN

Shadows in the graphics pipeline

csci 210: Data Structures Stacks and Queues

Data Structures And Algorithms

LR Parsing LALR Parser Generators

Compilers CS S-01 Compiler Basics & Lexical Analysis

Where are we going? EEC 521: Software Engineering. A Note on Quality. What is Design? Introduction to Design. Our focus

1. Write two major differences between Object-oriented programming and procedural programming?

4. Lexical and Syntax Analysis

Unit 1: Preliminaries Part 1: Course Introduction, Abstraction, and ADT s

Grading: 3 pts each part. If answer is correct but uses more instructions, 1 pt off. Wrong answer 3pts off.

Object-Oriented Programming Concepts

Outline and Reading. The Stack ADT ( 2.1.1) Applications of Stacks ( 2.1.1) Array-based implementation ( 2.1.1) Growable array-based stack ( 1.

UNIT I. 3. Write a short notes on process view of 4+1 architecture. 4. Why is object-oriented approach superior to procedural approach?

Compilers CS S-01 Compiler Basics & Lexical Analysis

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

Procedural abstraction SICP Data abstractions. The universe of procedures forsqrt. Procedural abstraction example: sqrt

Bottom-Up Parsing. Lecture 11-12

Transcription:

Abstraction עזאם מרעי המחלקה למדעי המחשב אוניברסיטת בן-גוריון

2 Tools for Programming Complex Software Fundamentally, people use only a few simple tools to create, understand, or manage complex systems One of the most important techniques is termed abstraction.

3 Roadmap In this chapter we will consider abstraction, which is the most important tool used in the control of complexity We will examine various abstraction mechanisms We will present a short history of the development of abstraction tools?

4 Abstraction Abstraction is the purposeful suppression, or hiding, of some details of a process or artifact, In order to bring out more clearly other aspects, details, or structure

5 \ Average Persons Understanding of an Automobile Device that takes fuel as input and produces a rotation of the drive shaft as output. A transmission is a mechanism used to reduce a rotation of several thousand revolutions per minute to a rotation of several revolutions per minute

6 Information Hiding Purposeful omission of details in the development of an abstract representation Information hiding is what allows abstraction to control complexity

7 Abstraction in an Atlas Think of an atlas, and the various different levels of maps: A map of the world, contains mountain ranges, large political boundaries A map of a continent, contains all political boundaries, large cities A map of a country, contains more cities, major roads A map of a large city, roads, major structures A map of a portion of a city, buildings, occupants

Levels of Abstraction in Object Oriented Programs 8

9 Levels of Abstraction in Object Oriented Programs At the highest level of abstraction we view a program as a community of interacting objects (and interacting programmers). Important characteristics here are the lines of communication between the various agents.

10 Abstraction in OO Programs -- Packages and Name spaces The next level of abstraction is found in some (but not all) object oriented languages A package, Unit or Name Space allows a programmer to surround a collection of objects (a small community in itself) with a layer, And control visibility from outside the module Package Data Structures

11 Abstraction in OO Languages -- Clients and Servers The next two levels of abstraction considers the relationship between two individual objects Typically one is providing a service, and the other is using the service Client Server Two layers of abstraction: view from the client side / view from the server side

12 Abstraction in OO languages -- Description of Services In a good object-oriented design we can describe the services that the server provides without reference to actions that the client may perform in using those services We define the nature of the services that are offered, but not how those services are realized. Joe s Data Structure Warehouse Services offered: void push(object val); $2.00 Object top(); $1.00 void pop(); $0.75

13 Levels of Abstraction in OO -- Interfaces Interfaces are one way to describe services at this level of abstraction: interface Stack { public void push (Object val); public Object top () throws EmptyStackException; public void pop () throws EmptyStackException; }

14 Levels of Abstraction An Implementation Next we look at the same boundary, but from the server side: public class LinkedList implements Stack... { public void pop () throws EmptyStackException {... }... } Concern here is with the high level approach to providing the designated service

15 Levels of Abstraction -- A Method in Isolation Finally, we consider the implementation of each method in isolation: public class LinkedList implements Stack... {... public void pop () throws EmptyStackException { if (isempty()) throw new EmptyStackException(); removefirst(); // delete first element of list }... }

16 Summary: Levels of Abstraction Interface Implementation Strategy Methods Every level is important, and often we move quickly back and forth between levels

17 The name of the game: Finding the right level of abstraction To determine what details are appropriate at each level of abstraction, And, more importantly, what details should be omitted One does not want to ignore or throw away important information But one does not want to manage too much information, Or have the amount of information hide critical details

Abstraction 18 Forms of Abstraction Division into parts Specialization Multiple views

19

20 Is-a and Has-A abstraction Two of the most important types of abstraction are the following: Division into parts -- Has-a abstraction Division into specialization -- Is-a abstraction Both is-a and has-a abstractions will reappear in later chapters and be tied to specific programming language features

21 Has-A Abstraction Division into parts takes a complex system, and divides into component parts, which can then be considered in isolation. Characterized by sentences that have the words has-a : A car has-an engine, and has-a transmission A bicycle has-a wheel A window has-a menu bar Allows us to drop down a level of complexity when we consider the component in isolation

22 Is-a Abstraction Is-a abstraction takes a complex system, and views it as an instance of a more general class Characterized by sentences that have the words is a : A car is a wheeled vehicle, which is-a means of transportation A bicycle is a wheeled vehicle A packhorse is a means of transportation Allows us to categorize artifacts and information and make it applicable to many different situations

23

24 Encapsulation and Interchangeability An important aspect of division into parts is to clearly characterize the connection, or interface, between to components Encapsulation: there is a strict division between the inner and the outer view Allows for considering multiple different implementations of the same interface Interchangeability For example, a car can have several different types of engine and one transmission

25

26 The Service View Another way to think of an interface is as a way of describing the service that an object provides The interface is a contract for the service If the interface is upheld, then the service will be provided as described. Joe s Data Structure Warehouse Services offered: void push(object val); $2.00 Object top(); $1.00 void pop(); $0.75

27 A measure for dependency: Coupling Coupling is the amount of dependency among modules. A system with many dependencies has high coupling. Good systems have low coupling Low coupling is a major pattern (advice) in assigning responsibilities to modules.

28 Coupling

29 Degree of Coupling The degree of coupling between two components can be qualitatively measured by determining the effects of changing the contract or interface between two components or systems. For example: What would happen if you added or deleted a property from a class? What would happen if you changed the data type of a column in a table? What would happen if you added a column to a table? What would happen if your database server changed from SQL Server to mysql or Oracle? The degree of pain that each of these changes would cause you is a good qualitative measurement of how tightly coupled your components are to the components they depend on

30 Low Coupling

31 Other Types of Abstraction -- Composition While is-a and has-a are two important types of abstraction, there are others Composition is one example; a form of has-a; characterized by the following: Primitive forms Rules for combining old values to create new values The idea that new values can also be subject to further combination Examples include regular expressions, type systems, windows, lots of other complex systems

32

33 Composition in the Creation of User Interfaces

34 Example of Composition Regular Expressions (empty set) denoting the empty set. (empty string) ε denoting the set containing only the "empty" string, which has no characters at all. (literal character) a in Σ denoting the set containing only the character a. (concatenation) RS denoting the set { αβ α in R and β in S }. For example {ab, c}{d, ef} = {abd, abef, cd, cef}. (alternation) R S denoting the set union of R and S. For example {ab, c} ab, d, ef = {ab, c, d, ef}. (Kleene star) R denoting the smallest superset of R that contains ε and is closed under string concatenation. This is the set of all strings that can be made by concatenating any finite number (including zero) of strings from R. For example, 0,1 is the set of all finite binary strings (including the empty string), and ab, c = {ε, ab, c, abab, abc, cab, cc, ababab, abcab, }.

35 Design Patterns Patterns are another attempt to document and reuse abstractions Patterns are description of proven and useful relationships between objects; which can help guide the solution of new problems Example pattern, Proxy: Client Proxy Server We ll have many more patterns in a later chapter

36 A Short History of Abstraction Mechanisms Another way to better understand OOP is to put it in context with the history of abstraction in computer science: i. Assembly languages ii. iii. iv. Procedures Modules ADT v. The Service View vi. vii. Objects The future...

37 ENIAC The First Electronic Computer

38 Assembly Languages Assembly languages and linkers were perhaps the first tools used to abstract features of the bare machine. Addresses could be represented symbolically, not as a number Symbolic names for operations Linking of names and locations performed automatically Binary 10110000 01100001 Hexa. B0 61 ASM MOV AL, 61h ; Load AL with 97 decimal (61 hex)

39 Procedures and Functions Libraries of procedures and functions (such as mathematical or input/output libraries) provided the first hints of information hiding They permit the programmer to think about operations in high level terms, concentrating on what is being done, not how it is being performed But they are not an entirely effective mechanism of information hiding

40 Information Hiding The Problem of Stacks int datastack[100]; int datatop = 0; void init() // initialize the stack { datatop = 0; } void push(int val) // push a value on to the stack { if (datatop < 100) datastack [datatop++] = val; } int top() // get the top of the stack { if (datatop > 0) return datastack [datatop - 1]; else return 0; } int pop() // pop element from the stack { if (datatop > 0) return datastack [--datatop]; else return 0; } Where can you hide the implementation?

41 Modules Modules basically provided collections of procedures and data With import and export statements Solves the problem of encapsulation

42 Parnas's Principles David Parnas described two principles for the proper use of modules: One must provide the intended user of a module with all the information needed to use the module correctly, and with nothing more One must provide the implementer of a module with all the information needed to complete the module, and nothing more

43 What if we need more than one stack?

44 Abstract Data Types An Abstract Data Type is a programmer-defined data type that can be manipulated in a manner similar to system-provided data types Must have the ability to instantiate many different copies of the data type Data type can be manipulated using provided operations, without knowledge of internal representation ADTs were important not because they were data structures, but because they provided an easily characterized service to the rest of an application

45 Modules and ADTs Modules are frequently used as an implementation technique for abstract data types modules are an implementation technique and that the abstract data type is a more theoretical concept. The two are related but are not identical

46 Modules and ADTs To build an abstract data type 1. Export a type definition. 2. Make available a set of operations that can be used to manipulate instances of the type. 3. Protect the data associated with the type so that they can be operated on only by the provided routines. 4. Make multiple instances of the type

47 Three Eons of History Looking at this history, we can separate it into three periods of time: Functionality of the application Data types used in an application services provided by objects in the application

48 Objects - ADT's with Message Passing Characteristics of Objects: Encapsulation -- similar to modules Instantiation -- similar to ADT's Messages -- dynamic binding of procedure names to behavior Classes -- a way of organization that permits sharing and reuse Polymorphism -- A new form of software reuse using dynamic binding

49 OMG one picture MDA Vertical Domains Core Technologies Core Target Platforms Pervasive Services

50 What Does the Future Hold What will be the next evolutionary step in software? Prediction is hard, particularly about the future However, once you have accepted the idea of an application formed from interacting agents: There is no reason why those components must exist on the same computer (distributed computing) Or be written in the same language (components) So some of the trends we see today in software are natural results of the OOP mind set